
function [tnotas, erros_onset, acertos_onset, erros_offset, acertos_offset] = contaerro()

% contabilização dos erros dos dois dias(canadá) com a revisão do davi

%primeiro dia




 y(1) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq1_arp1_C.txt');
 y(2) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq1_arp1_E.txt');
 y(3) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq1_arp2_C.txt');
 y(4) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq1_arp2_E.txt');
 y(5) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq1_th1_C.txt');
 y(6) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq1_th1_E.txt');
 y(7) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq1_th1_ph2_C.txt');
 y(8) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq1_th1_ph2_E.txt');
 y(9) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq1_th2_C.txt');
 y(10) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq1_th2_E.txt');
 y(11) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq2_coda_C.txt');
 y(12) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq2_coda_E.txt');
 y(13) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq2_th1_C.txt');
 y(14) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq2_th1_E.txt');
 y(15) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq4_var1_ph1_C.txt');
 y(16) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq4_var1_ph1_E.txt');
 y(17) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq4_var1_ph2_C.txt');
 y(18) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\mozartq4_var1_ph2_E.txt');
 y(19) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\scale 4-4-dotted.txt');
 y(20) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\scale 4-4-legato.txt');
 y(21) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\scale 4-4-staccato.txt');






yr(1) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq1_arp1_C.txt');
yr(2) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq1_arp1_E.txt');
yr(3) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq1_arp2_C.txt');
yr(4) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq1_arp2_E.txt');
yr(5) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq1_th1_C.txt');
yr(6) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq1_th1_E.txt');
yr(7) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq1_th1_ph2_C.txt');
yr(8) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq1_th1_ph2_E.txt');
yr(9) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq1_th2_C.txt');
yr(10) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq1_th2_E.txt');
yr(11) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq2_coda_C.txt');
yr(12) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq2_coda_E.txt');
yr(13) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq2_th1_C.txt');
yr(14) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq2_th1_E.txt');
yr(15) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq4_var1_ph1_C.txt');
yr(16) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq4_var1_ph1_E.txt');
yr(17) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq4_var1_ph2_C.txt');
yr(18) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rmozartq4_var1_ph2_E.txt');
yr(19) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rscale_4-4-dotted.txt');
yr(20) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rscale_4-4-legato.txt');
yr(21) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-27\Rscale_4-4-staccato.txt');




%segundo dia

z(1) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc1_th1_ph1_C.txt');
z(2) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc1_th1_ph1_E.txt');
z(3) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc2_th1_ph1_C.txt');
z(4) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc2_th1_ph1_E.txt');
z(5) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc2_th1_ph2_C.txt');
z(6) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc2_th1_ph2_E.txt');
z(7) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc2_th2_var1_C.txt');
z(8) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc2_th2_var1_E.txt');
z(9) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc2_th2_var2_C.txt');
z(10) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc2_th2_var2_E.txt');
z(11) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc3_th1_ph1_C.txt');
z(12) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc3_th1_ph1_E.txt');
z(13) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc3_th1_ph2&1_C.txt');
z(14) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc3_th1_ph2&1_E.txt');
z(15) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc3_th2_C.txt');
z(16) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartc3_th2_E.txt');
z(17) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq1_arp1_C.txt');
z(18) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq1_arp1_E.txt');
z(19) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq1_arp2_C.txt');
z(20) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq1_arp2_E.txt');
z(21) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq1_th1_C.txt');
z(22) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq1_th1_E.txt');
z(23) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq1_th1_ph2_C.txt');
z(24) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq1_th1_ph2_E.txt');
z(25) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq1_th2_C.txt');
z(26) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq1_th2_E.txt');
z(27) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq2_coda_C.txt');
z(28) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq2_coda_E.txt');
z(29) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq2_th1_C.txt');
z(30) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq2_th1_E.txt');
z(31) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq4_var1_ph1_C.txt');
z(32) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq4_var1_ph1_E.txt');
z(33) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq4_var1_ph2_C.txt');
z(34) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\mozartq4_var1_ph2_E.txt');



zr(1) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc1_th1_ph1_C.txt');
zr(2) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc1_th1_ph1_E.txt');
zr(3) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc2_th1_ph1_C.txt');
zr(4) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc2_th1_ph1_E.txt');
zr(5) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc2_th1_ph2_C.txt');
zr(6) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc2_th1_ph2_E.txt');
zr(7) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc2_th2_var1_C.txt');
zr(8) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc2_th2_var1_E.txt');
zr(9) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc2_th2_var2_C.txt');
zr(10) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc2_th2_var2_E.txt');
zr(11) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc3_th1_ph1_C.txt');
zr(12) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc3_th1_ph1_E.txt');
zr(13) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc3_th1_ph2&1_C.txt');
zr(14) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc3_th1_ph2&1_E.txt');
zr(15) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc3_th2_C.txt');
zr(16) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartc3_th2_E.txt');
zr(17) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq1_arp1_C.txt');
zr(18) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq1_arp1_E.txt');
zr(19) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq1_arp2_C.txt');
zr(20) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq1_arp2_E.txt');
zr(21) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq1_th1_C.txt');
zr(22) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq1_th1_E.txt');
zr(23) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq1_th1_ph2_C.txt');
zr(24) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq1_th1_ph2_E.txt');
zr(25) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq1_th2_C.txt');
zr(26) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq1_th2_E.txt');
zr(27) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq2_coda_C.txt');
zr(28) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq2_coda_E.txt');
zr(29) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq2_th1_C.txt');
zr(30) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq2_th1_E.txt');
zr(31) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq4_var1_ph1_C.txt');
zr(32) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq4_var1_ph1_E.txt');
zr(33) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq4_var1_ph2_C.txt');
zr(34) = readpraat('C:\Documents and Settings\Campolinas.HOME\Desktop\canada\txts_do_praat\2007-06-28\Rmozartq4_var1_ph2_E.txt');

y = [y z];     % onsets e offsets do codigo
yr = [yr zr];  % onsets e offsets revisados

notas = 0;
erros_on = 0;
acertos_on = 0;
erros_of = 0;
acertos_of = 0;
acerton = 0;
acertof = 0;
% m_er = 0.0;  %margem de erro: tempo em seg de um quadro 
% m_er = 0.0232;  %margem de erro: tempo em seg de um quadro 
% m_er = 2*0.0232;  %margem de erro: tempo em seg de um quadro 
 m_er = 2.5*0.0232;  %margem de erro: tempo em seg de um quadro 


for i=1:length(yr)
    tam_on = length(yr(i).onset);
    tam_of = length(yr(i).offset);
    notas_locais = tam_on;         % notas = numero de onsets do gabarito
    notas = notas + notas_locais;
    
    % onsets
    for j=1:tam_on
        pr = yr(i).onset(j);  % valor de onset do gabarito
        acert = length(find((y(i).onset>=(pr-m_er)) & (y(i).onset<=(pr+m_er))));    
        acerton = acerton + acert;       
    end
    acertos_on = acertos_on + acerton;
    sil_anton = length(find(y(i).onset < yr(i).onset(1))); %deteccoes no silencio anterior
    sil_poson = length(find(y(i).onset > yr(i).onset(tam_on)));%deteccoes no silencio posterior
    erros_on = erros_on + (length(y(i).onset) - acerton - sil_anton - sil_poson);
    acerton = 0;
    
    %offsets
    for j=1:tam_of
        pr = yr(i).offset(j);  % valor de onset do gabarito
        acert = length(find((y(i).offset>=(pr-m_er)) & (y(i).offset<=(pr+m_er))));    
        acertof = acertof + acert;
    end
    acertos_of = acertos_of + acertof;
    sil_antof = length(find(y(i).offset < yr(i).offset(1))); %deteccoes no silencio anterior
    sil_posof = length(find(y(i).offset > yr(i).offset(tam_on)));%deteccoes no silencio posterior
    erros_of = erros_of + (length(y(i).offset) - acertof - sil_antof - sil_posof);
    acertof = 0;  
end    

tnotas = notas;
erros_onset = erros_on; 
acertos_onset = acertos_on;
erros_offset = erros_of;
acertos_offset = acertos_of;


